﻿using Share;

public class StateBase
{
    ObjectBase m_Owner;
    string m_strName;

    public ObjectState Owner
    {
        get { return m_Owner as ObjectState; }
    }

    public string Name
    {
        get { return m_strName; }
    }
    public void DoInit(string strName, ObjectBase Owner)
    {
        m_Owner = Owner;
        m_strName = strName;
        OnInit();
    }
    protected virtual void OnInit()
    {

    }
    //发送消息给状态
    public virtual void DoSendEvent(EventParam param)
    {

    }
    // 强行结束
    public virtual void DoForceEnd()
    {

    }
    public virtual bool IsLockFace()
    {
        return false;
    }
    public virtual bool IsNeedCheckGround()
    {
        return true;
    }
    public virtual bool IsNeedCheckUp()
    {
        return true;
    }

    public bool DoUpdate()
    {
        return OnUpdate();
    }
    protected virtual void OnAnimationEnd()
    {

    }
    protected virtual bool OnUpdate()
    {
        return true;
    }
    // 状态开始
    public bool DoStart(EventParam param)
    {
        if (OnStart(param))
        {
            Owner.DoSendStateEnterMessage(Name);
            return true;
        }
        return false;
    }
    protected virtual bool OnStart(EventParam param)
    {
        TranslateParam(param);
        return true;
    }

    // 状态重置
    public bool DoRestart(EventParam param)
    {
        if (OnRestart(param))
        {
            Owner.DoSendStateEnterMessage(Name);
            return true;
        }
        return false;
    }
    protected virtual bool OnRestart(EventParam param)
    {
        TranslateParam(param);
        return true;
    }

    // 这个状态是否可以转换到新的状态
    public virtual bool IsCanTransition(string strNewState)
    {
        return true;
    }

    /// <summary>
    /// 是否可以
    /// </summary>
    /// <returns></returns>

    //自动转到指定的状态
    public virtual bool GoNextState()
    {
        return true;
    }

    protected virtual void TranslateParam(EventParam param)
    {

    }
    #region 状态终止
    // 强行打断
    public virtual void DoBreak()
    {

    }
    // 结束这个状态 
    public virtual void DoEnd()
    {

    }
    //停止这个状态
    public virtual void DoStop()
    {

    }
    //释放并且删除这个状态
    public virtual void DoRelease()
    {

    }
    #endregion
}






